#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libxml/parser.h>
#include <libxml/tree.h>

void dump_args(xmlNodePtr cur, int depth)
{
    //if (depth >= 5) return;
    while (cur) {
        if (cur->type == XML_ELEMENT_NODE) {
            if (cur->xmlChildrenNode->type == XML_TEXT_NODE && cur->xmlChildrenNode->next == NULL) printf("arg %s\n", cur->name);
        }
        xmlNodePtr n = cur->xmlChildrenNode;
        while (n) {
            dump_args(n, depth + 1);
            n = n->xmlChildrenNode;
        }
        cur = cur->next;
    }
}

int main(int argc, char **argv)
{
#define xmlstr "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"\
"<soapenv:Envelope xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"\n"\
" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n"\
" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n"\
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"\
"<soapenv:Body>\n"\
"<WaitForUpdatesEx xmlns=\"urn:vim25\"><_this type=\"PropertyCollector\">ha-property-collector</_this><version xsi:type=\"xsd:string\">3</version><options xsi:type=\"WaitOptions\"><maxWaitSeconds xsi:type=\"xsd:int\">300</maxWaitSeconds></options></WaitForUpdatesEx>\n"\
"</soapenv:Body>\n"\
"</soapenv:Envelope>"
    printf("\n");
    printf("xml:\n%s\n\n", xmlstr);
    //xmlDocPtr doc = xmlReadMemory(xmlstr, strlen(xmlstr), NULL, NULL, 0);
    //xmlDocPtr doc = xmlReadMemory(xmlstr, strlen(xmlstr), "test", NULL, 0);
    xmlDocPtr doc = xmlParseDoc(  xmlstr);
    if (doc) {
        xmlNodePtr cur;
        cur = xmlDocGetRootElement(doc); // 获取根节点
        dump_args(cur, 1);
        xmlFreeDoc(doc);
    }
}

